

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
	public class busLinks:BusinessBase
	{
		public busLinks() : base()
		{
		}
		#region  Code Factory Generated Methods


		public DataTable SelectLinks()
		{
			try
			{
				datLinks insDatLinks = new datLinks();
				DbConnector insDbConnector = new DbConnector();
				return insDatLinks.SelectLinks(insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage = ex.Message;
			}
			return null;
		}
		public void SelectLinksByLinkId(entLinks parEntLinks)
		{
			try
			{
				datLinks insDatLinks = new datLinks();
				DbConnector insDbConnector = new DbConnector();
				insDatLinks.SelectLinksByLinkId(parEntLinks, insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage=ex.Message;
			}
		}
		
		#endregion

        public DataTable SelectLinksRandom()
        {
            try
            {
                datLinks insDatLinks = new datLinks();
                DbConnector insDbConnector = new DbConnector();
                return insDatLinks.SelectLinksRandom(insDbConnector);
                
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public DataTable SelectLinksByLanguageId()
        {
            try
            {
                datLinks insDatLinks = new datLinks();
                DbConnector insDbConnector = new DbConnector();
                return insDatLinks.SelectLinksByLanguageId(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }

        public void InsertLinks(entLinks parEntLinks)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datLinks insDatLinks = new datLinks();
                insDatLinks.InsertLinks(parEntLinks, insDbConnector);
                datLinkContents insDatLinkContents = new datLinkContents();
                foreach (entLinkContents insEntLinkContents in parEntLinks.LinkContentsInsert)
                {
                    insEntLinkContents.LinkId = parEntLinks.LinkId;
                    insDatLinkContents.InsertLinkContents(insEntLinkContents, insDbConnector);
                }
                foreach (entLinkContents insEntLinkContents in parEntLinks.LinkContentsUpdate)
                {
                    insEntLinkContents.LinkId = parEntLinks.LinkId;
                    insDatLinkContents.UpdateLinkContentsByLinkContentId(insEntLinkContents, insDbConnector);
                }
                foreach (entLinkContents insEntLinkContents in parEntLinks.LinkContentsDelete)
                {
                    insDatLinkContents.DeleteLinkContentsByLinkContentId(insEntLinkContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void UpdateLinksByLinkId(entLinks parEntLinks)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datLinks insDatLinks = new datLinks();
                insDatLinks.UpdateLinksByLinkId(parEntLinks, insDbConnector);
                datLinkContents insDatLinkContents = new datLinkContents();
                foreach (entLinkContents insEntLinkContents in parEntLinks.LinkContentsInsert)
                {
                    insEntLinkContents.LinkId = parEntLinks.LinkId;
                    insDatLinkContents.InsertLinkContents(insEntLinkContents, insDbConnector);
                }
                foreach (entLinkContents insEntLinkContents in parEntLinks.LinkContentsUpdate)
                {
                    insEntLinkContents.LinkId = parEntLinks.LinkId;
                    insDatLinkContents.UpdateLinkContentsByLinkContentId(insEntLinkContents, insDbConnector);
                }
                foreach (entLinkContents insEntLinkContents in parEntLinks.LinkContentsDelete)
                {
                    insDatLinkContents.DeleteLinkContentsByLinkContentId(insEntLinkContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void DeleteLinksByLinkId(entLinks parEntLinks)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
datLinkContents insDatLinkContents = new datLinkContents();
entLinkContents insEntLinkContents = new entLinkContents();
insEntLinkContents.LinkId = parEntLinks.LinkId;
                insDatLinkContents.DeleteLinkContentsByLinkId(insEntLinkContents,insDbConnector);

                datLinks insDatLinks = new datLinks();
                insDatLinks.DeleteLinksByLinkId(parEntLinks, insDbConnector);
                

                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
	}
}